define([
        'app/utils/WebUtils',
        'app/service/GeneralServices',
        'underscore',
        'app/utils/UploadLogoUtils',
        'app/utils/AMUICookieUtils',
        'app/utils/CommonUtils'
        
        
        ], function (
        WebUtils,
        gs,
        _,
        UploadLogoUtils,
        AMUICookieUtils
    ) {
	
	
	var opt ={};
	var p1 = {};
	opt = AMUICookieUtils.initializePage(true);
	p1 = AMUICookieUtils.initializePage(true);

	
	p1.useruuid = $.getUrlParam("useruuid");
	
	gs.wjt_user_init(p1, function(resp){
		if(resp.status == "500"){
			WebUtils.alert("连接错误，请刷新页面重试！");	
			return;
		}
		
		opt.navi_main = "编辑资料";
		opt.navi_sub = "编辑用户信息";
		
		opt.copyrighttext = "";//"© 2016 版权所有 中研沃兮网络科技（上海）有限公司";
		
		WebUtils.adminPageInt(opt);
		
		WebUtils.inputInt($("#wjt_user_name"), resp.result.user.name);
		WebUtils.inputInt($("#wjt_user_email"), resp.result.user.email);
		WebUtils.inputInt($("#wjt_user_phone"), resp.result.user.tel);
		WebUtils.imageInt($("#wjt_user_thumb"), resp.result.user.wxHeadimgurl);
		
	});
	
	
	//tab1
	
	var url = "/wjt/upload_user_thumb/"+p1.useruuid;
	UploadLogoUtils.initSingleImage("wjt_user_thumb_upload_container","wjt_user_thumb_upload_btn",url,
		function(up, file, info){
			console.log(up);
			console.log(file);
			console.log(info);
			var resp = JSON.parse(info.response);
			console.log(resp);

			//tab2 refresh...
			$.setUrlParam("tab","1");
			//"{"status":"200","result":{"path":"http://localhost:8014/attachment/img/ac3f7f1d-4462-4362-8363-8a08826ebe82","key":"ac3f7f1d-4462-4362-8363-8a08826ebe82"}}"
		});

	
	$("#wjt_user_info_save").click(function(){
		
		var name = $("#wjt_user_name").val();
		var phone = $("#wjt_user_phone").val();
		var email = $("#wjt_user_email").val();
		
		if($.isNullStr(name)){
			WebUtils.alert("名字不能为空");
			return;
		}
		if(!$.isEmail(email)){
			WebUtils.alert("请正确输入邮件地址");
			return;
		}
		if(!$.isTel(phone)){
			WebUtils.alert("请正确输入手机号");
			return;
		}

		var p = {
			useruuid:p1.useruuid,
			name:name,
			email:email,
			phone:phone
		};
		gs.userinfo_udpate(p,function(resp){
			if(resp.status != "200"){
				WebUtils.alert("操作未成功，请重试");
				return;
			}
			$.setUrlParam("tab","1");
		});
	});
	
	
	
	//tab2 
	$(".userinfo-pwd-save").click(function(){
		var $btn = $(this);
		$btn.button('loading');
		var p ={
			"useruuid":p1.useruuid,
			"wjt_user_pwd_new":$("#wjt_user_pwd_new").val()
		};
		
		if($.isNullStr($("#wjt_user_pwd_new").val())){
			WebUtils.alert("新密码不能为空！");	
			$btn.button('reset');
			return;
		}
		
		gs.userinfo_admin_pwd_update(p,function(resp){
			
			$btn.button('reset');
			
			if(resp.status == "500"){
				if($.isNullStr(resp.result)){
					WebUtils.alert("操作不成功，请重试！");					
				}else{
					WebUtils.alert(resp.result);
				}
			}else{
				WebUtils.alert("修改成功");		
				WebUtils.inputClear($("#wjt_user_pwd_new"));
			}
			
		});
	});
	

	$(".userinfo-pwd-cancel").click(function(){
		WebUtils.inputClear($("#wjt_user_pwd_new"));
	});
	
	return;
});